package com.authine.cloudpivot.ext.applicationservice;

import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.applicationservice.base.ApplicationBaseService;
import com.authine.cloudpivot.ext.constants.AppConst;
import com.authine.cloudpivot.ext.constants.ModelConst;
import com.authine.cloudpivot.ext.constants.PlatformConst;
import com.authine.cloudpivot.ext.dto.transfer.*;
import com.authine.cloudpivot.ext.enums.finance.PaymentStatusEnum;
import com.authine.cloudpivot.ext.enums.order.OrderGoodsStatusEnum;
import com.authine.cloudpivot.ext.enums.order.transfer.*;
import com.authine.cloudpivot.ext.enums.report.ReportType;
import com.authine.cloudpivot.ext.service.TransferOrderService;
import com.authine.cloudpivot.ext.service.impl.TransferOrderServiceImpl;
import com.authine.cloudpivot.ext.utils.*;
import com.authine.cloudpivot.ext.utils.boQuery.BoQueryUtils;
import com.authine.cloudpivot.ext.utils.system.ReportUtils;
import com.authine.common.json.JsonUtils;
import com.authine.common.util.DateUtils;
import com.authine.mvp.app.launcher.domain.utills.ApplicationContextUtils;
import com.authine.mvp.app.launcher.dto.bo.response.BO;
import com.authine.mvp.app.launcher.dto.bo.response.BOList;
import com.authine.mvp.app.launcher.rpc.SaveOrUpdateBO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

/**
 * @ClassName TransferManageOrderService
 * @Description: 转采管理自定义服务
 * @Author cjj
 * @Date 2021/6/18
 * @Version V1.0
 **/
@Path("TransferManageOrderService")
@Slf4j
public class TransferManageOrderService extends ApplicationBaseService {
    private TransferOrderService transferOrderService = new TransferOrderServiceImpl();
    private NamedParameterJdbcTemplate jdbcTemplate = ApplicationContextUtils.getBean(NamedParameterJdbcTemplate.class);

    /**
     * 转采客户订单商品分页列表/采购商品历史分页列表
     *
     * @param dto
     * @return
     */
    @Path("transferOrderGoods")
    @POST
    @Operation(summary = "转采管理-转采客户订单商品列表分页查询/转采管理-采购商品历史列表分页查询", tags = CUSTOM_SERVICE, description = "pageIndex、pageSize、not_purchase、del必填")
    public SingleResponse<BOList> transferOrderGoods(@Parameter TransferOrderGoodsDto dto) {
        log.info("------------------------转采管理-转采客户订单商品列表分页查询/转采管理-采购商品历史列表分页查询 transferOrderGoods Param：{}------------------------", JsonUtils.toJson(dto));
        if (null == dto.getPageIndex() || null == dto.getPageSize()) {
            return SingleResponse.buildFailure("-1", "pageIndex、pageSize必填");
        }
        if (null == dto.getNot_purchase()) {
            return SingleResponse.buildFailure("-1", "是否再次采购必填");
        }
        String transferOrderTableName = getTableName(ModelConst.T_TRANSFER_ORDER);
        String transferOrderGoodsTableName = getTableName(ModelConst.T_TRANSFER_ORDER_GOODS);
        String orderGoodsReturnsTableName = getTableName(AppConst.ORDER_CENTER, ModelConst.T_ORDER_GOODS_RETURNS);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        StringBuilder countSql = new StringBuilder();
        listSql.append("SELECT case when tg.returns_quantity is null or tg.returns_quantity = '' then gr.quantity else null end as returns_quantity," +
                "case when t.order_type='Contract' then '是' else '否' end as is_contract," +
                "case when tg.purchasing_agent_id is null or tg.purchasing_agent_id = '' then '是' else '否' end as is_assign_buyer," +
                " tg.*, t.* FROM " + transferOrderGoodsTableName + " tg " +
                "LEFT JOIN " + transferOrderTableName + " t on tg.transfer_order_id = t.id " +
                "LEFT JOIN " + orderGoodsReturnsTableName + " gr on gr.order_customer_goods_id = tg.cloud_order_goods_id " +
                "WHERE t.order_type='purchase'");
        countSql.append("SELECT count(*) FROM " + transferOrderGoodsTableName + " tg " +
                "LEFT JOIN " + transferOrderTableName + " t on tg.transfer_order_id = t.id " +
                "LEFT JOIN " + orderGoodsReturnsTableName + " gr on gr.order_customer_goods_id = tg.cloud_order_goods_id " +
                "WHERE t.order_type='purchase'");
        //拼接参数
        if (null != dto.getNot_purchase()) {
            whereSql.append(" and tg.not_purchase = :not_purchase ");
            parameter.put("not_purchase", dto.getNot_purchase());
        }
        //平台客户订单号
        if (StringUtils.isNotBlank(dto.getCloud_order_id())) {
            List<String> cloudOrderIds = StringUtils.stringToListString(dto.getCloud_order_id(), ";");
            whereSql.append(" and t.cloud_order_id in (:cloud_order_id) ");
            parameter.put("cloud_order_id", cloudOrderIds);
        }
        //平台客户订单商品号
        if (StringUtils.isNotBlank(dto.getCloud_order_goods_id())) {
            List<String> cloudOrderGoodsIds = StringUtils.stringToListString(dto.getCloud_order_goods_id(), ";");
            whereSql.append(" and tg.cloud_order_goods_id in (:cloud_order_goods_id) ");
            parameter.put("cloud_order_goods_id", cloudOrderGoodsIds);
        }
        //询价单号
        if (StringUtils.isNotBlank(dto.getInquiry_id())) {
            List<String> inquiryIds = StringUtils.stringToListString(dto.getInquiry_id(), ";");
            whereSql.append(" and tg.inquiry_id in (:inquiry_id) ");
            parameter.put("inquiry_id", inquiryIds);
        }
        //名称
        if (StringUtils.isNotBlank(dto.getName())) {
            whereSql.append(" and tg.name like :name ");
            parameter.put("name", "%" + dto.getName() + "%");
        }
        //品牌
        if (StringUtils.isNotBlank(dto.getBrand())) {
            whereSql.append("and tg.brand like :brand ");
            parameter.put("brand", "%" + dto.getBrand() + "%");
        }
        //型号
        if (StringUtils.isNotBlank(dto.getModel())) {
            whereSql.append(" and tg.model like :model ");
            parameter.put("model", "%" + dto.getModel() + "%");
        }
        //供应商
        if (StringUtils.isNotBlank(dto.getVendor_name())) {
            whereSql.append(" and tg.vendor_name like :vendor_name ");
            parameter.put("vendor_name", "%" + dto.getVendor_name() + "%");
        }
        //下单组织
        if (StringUtils.isNotBlank(dto.getOrganization_name())) {
            whereSql.append(" and t.organization_name like :organization_name ");
            parameter.put("organization_name", "%" + dto.getOrganization_name() + "%");
        }
        //平台组织名称
        if (StringUtils.isNotBlank(dto.getPlatform_name())) {
            whereSql.append(" and t.platform_name like :platform_name ");
            parameter.put("platform_name", "%" + dto.getPlatform_name() + "%");
        }
        //采购员
        if (StringUtils.isNotBlank(dto.getPurchase_agent_name())) {
            whereSql.append(" and tg.purchase_agent_name like :purchase_agent_name ");
            parameter.put("purchase_agent_name", "%" + dto.getPurchase_agent_name() + "%");
        }
        //商品状态
        if (StringUtils.isNotBlank(dto.getTransfer_order_goods_status())) {
            whereSql.append(" and tg.transfer_order_goods_status = :transfer_order_goods_status ");
            parameter.put("transfer_order_goods_status", dto.getTransfer_order_goods_status());
        }
        //下单日期
        if (!CollectionUtils.isEmpty(dto.getCreatedTimes()) && dto.getCreatedTimes().size() >= 2) {
            whereSql.append(" and t.createdTime between :startTime and :endTime ");
            parameter.put("startTime", dto.getCreatedTimes().get(0));
            parameter.put("endTime", dto.getCreatedTimes().get(1));
        }
        //未分配采购员
        if (null != dto.getIs_assign_buyer() && dto.getIs_assign_buyer()) {
            whereSql.append(" and (tg.purchasing_agent_id is null or tg.purchasing_agent_id = '') ");
        }
        countSql.append(whereSql);
        listSql.append(whereSql);
        listSql.append(" order by tg.createdTime desc");
        listSql.append(" limit " + dto.getPageIndex() * dto.getPageSize() + ", " + dto.getPageSize());
        log.info("------------------------转采管理-转采客户订单商品列表分页查询/转采管理-采购商品历史列表分页查询 transferOrderGoods listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(listSql.toString(), parameter);
        Integer count = 0;
        try {
            count = jdbcTemplate.queryForObject(countSql.toString(), parameter, Integer.class);
        } catch (DataAccessException e) {
            e.printStackTrace();
        }
        //构建结果集
        BoResultFormat.resultFormat(resultList, ModelConst.T_TRANSFER_ORDER_GOODS);
        BOList bOList = new BOList();
        bOList.setData(resultList);
        bOList.setTotal(count);
        bOList.setSchemaCode(ModelConst.T_TRANSFER_ORDER_GOODS);
        return SingleResponse.of(bOList);
    }

    /**
     * 转采管理-转采客户订单商品-分配采购员-提交选择采购员
     *
     * @param dto
     * @return
     */
    @Path("savePurchasingAgent")
    @POST
    @Operation(summary = "转采管理-转采客户订单商品-分配采购员-提交选择采购员", tags = CUSTOM_SERVICE, description = "ids、purchasing_agent_id必填")
    public SingleResponse<Boolean> savePurchasingAgent(@Parameter TransferOrderGoodsDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "转采订单商品ID集合必填");
        }
        if (StringUtils.isBlank(dto.getPurchasing_agent_id())) {
            return SingleResponse.buildFailure("-1", "采购人必填");
        }
        boolean flag = transferOrderService.updatePurchaseAgent(dto.getIds(), dto.getPurchasing_agent_id());
        return SingleResponse.of(flag);
    }

    /**
     * 转采管理-转采客户订单商品-生成采购订单
     *
     * @param dto
     * @return
     */
    @Path("saveTransferOrder")
    @POST
    @Operation(summary = "转采管理-转采客户订单商品-生成采购订单", tags = CUSTOM_SERVICE, description = "payment_id、vendor_id、memberPurchaseOrderGoods必填")
    public SingleResponse<BO> saveTransferOrder(@Parameter MemberPurchaseOrderDto dto) {
        if (null == dto) {
            return SingleResponse.buildFailure("-1", "转采订单必填");
        }
        if (CollectionUtils.isEmpty(dto.getMemberPurchaseOrderGoods())) {
            return SingleResponse.buildFailure("-1", "转采订单商品集合必填");
        }
        SingleResponse<BO> result = transferOrderService.submitTransferOrder(dto);
        return result;
    }

    /**
     * 转采管理-转采客户订单商品-标记已采购/转采管理-采购商品历史-返回待采
     *
     * @param dto
     * @return
     */
    @Path("markPurchased")
    @POST
    @Operation(summary = "转采管理-转采客户订单商品-标记已采购/转采管理-采购商品历史-返回待采", tags = CUSTOM_SERVICE, description = "ids、notPurchase(true：为标价已采购 false：为返回待采)、reason必填")
    public SingleResponse<Boolean> markPurchased(@Parameter TransferOrderGoodsDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "转采订单商品ID集合必填");
        }
        if (StringUtils.isBlank(dto.getNot_purchase())) {
            return SingleResponse.buildFailure("-1", "是否再次采购必填");
        }
        if (StringUtils.isBlank(dto.getReason())) {
            return SingleResponse.buildFailure("-1", "标记已采购原因必填");
        }
        boolean flag = transferOrderService.tagPurchaseGoods(dto.getIds(), dto.getNot_purchase(), dto.getReason());
        return SingleResponse.of(flag);
    }

    /**
     * 转采管理-采购订单列表
     *
     * @param dto
     * @return
     */
    @Path("transferPurchaseOrderList")
    @POST
    @Operation(summary = "转采管理-采购订单列表分页查询", tags = CUSTOM_SERVICE, description = "pageIndex、pageSize必填")
    public SingleResponse<BOList> transferPurchaseOrderList(@Parameter MemberPurchaseOrderDto dto) {
        log.info("------------------------转采管理-采购订单列表分页查询 transferPurchaseOrderList Param：{}------------------------", JsonUtils.toJson(dto));
        if (null == dto.getPageIndex() || null == dto.getPageSize()) {
            return SingleResponse.buildFailure("-1", "pageIndex、pageSize必填");
        }
        String mpoTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER);
        String paTableName = getTableName(ModelConst.T_PAY_ACCOUNT);
        String pwTableName = getTableName(ModelConst.T_PAYMENT_WAY);
        String tvTableName = getTableName(ModelConst.T_TRANSFER_ORDER);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        StringBuilder countSql = new StringBuilder();
        listSql.append("select * from " + mpoTableName + " mpo " +
                " LEFT JOIN " + pwTableName + " pw on mpo.payment_id = pw.id " +
                " LEFT JOIN " + paTableName + " pa on mpo.pay_account_id = pw.id " +
                " LEFT JOIN " + tvTableName + " tv on mpo.vendor_id = tv.id where mpo.deleted = '0' ");
        countSql.append("select count(*) from " + mpoTableName + " mpo " +
                " LEFT JOIN " + pwTableName + " pw on mpo.payment_id = pw.id " +
                " LEFT JOIN " + paTableName + " pa on mpo.pay_account_id = pw.id " +
                " LEFT JOIN " + tvTableName + " tv on mpo.vendor_id = tv.id  where mpo.deleted = '0'");
        //采购单ID
        if (StringUtils.isNotBlank(dto.getId())) {
            List<String> ids = StringUtils.stringToListString(dto.getId(), ";");
            whereSql.append(" and mpo.id in (:id) ");
            parameter.put("id", ids);
        }
        //采购P单
        if (StringUtils.isNotBlank(dto.getPo_code())) {
            List<String> poCodes = StringUtils.stringToListString(dto.getPo_code(), ";");
            whereSql.append(" and mpo.po_code in (:po_code) ");
            parameter.put("po_code", poCodes);
        }
        //云平台订单
        if (StringUtils.isNotBlank(dto.getCloud_order_ids())) {
            List<String> cloudOrderIds = StringUtils.stringToListString(dto.getCloud_order_ids(), ";");
            whereSql.append(" and mpo.cloud_order_ids in (:cloud_order_ids) ");
            parameter.put("cloud_order_ids", cloudOrderIds);
        }
        //采购员
        if (StringUtils.isNotBlank(dto.getBuyer())) {
            whereSql.append(" and mpo.buyer like :buyer ");
            parameter.put("buyer", "%" + dto.getBuyer() + "%");
        }
        //供应商
        if (StringUtils.isNotBlank(dto.getVendor_id())) {
            whereSql.append(" and tv.company_name like :vendor_id ");
            parameter.put("vendor_id", "%" + dto.getVendor_id() + "%");
        }
        //客户
        if (StringUtils.isNotBlank(dto.getCustomer_name())) {
            whereSql.append(" and mpo.customer_name like :customer_name ");
            parameter.put("customer_name", "%" + dto.getCustomer_name() + "%");
        }
        //备注
        if (StringUtils.isNotBlank(dto.getMemo())) {
            whereSql.append(" and mpo.memo like :memo ");
            parameter.put("memo", "%" + dto.getMemo() + "%");
        }
        //付款方式
        if (StringUtils.isNotBlank(dto.getPayment_id())) {
            whereSql.append(" and mpo.payment_id = :payment_id ");
            parameter.put("payment_id", dto.getPayment_id());
        }
        //平台组织名称
        if (StringUtils.isNotBlank(dto.getPlatform_name())) {
            whereSql.append(" and mpo.platform_name like :platform_name ");
            parameter.put("platform_name", "%" + dto.getPlatform_name() + "%");
        }
        //采购单付款状态
        if (StringUtils.isNotBlank(dto.getMember_purchase_order_status())) {
            whereSql.append(" and mpo.member_purchase_order_status = :member_purchase_order_status ");
            parameter.put("member_purchase_order_status", dto.getMember_purchase_order_status());
        }
        //采购单收票状态
        if (StringUtils.isNotBlank(dto.getInvoice_status())) {
            whereSql.append(" and mpo.invoice_status = :invoice_status ");
            parameter.put("invoice_status", dto.getInvoice_status());
        }
        //付款方式
        if (StringUtils.isNotBlank(dto.getPlatform_name())) {
            whereSql.append(" and mpo.payment_name like :payment_name ");
            parameter.put("payment_name", "%" + dto.getPlatform_name() + "%");
        }
        //发票类型
        if (StringUtils.isNotBlank(dto.getInvoice_type())) {
            whereSql.append(" and mpo.invoice_type = :invoice_type ");
            parameter.put("invoice_type", dto.getInvoice_type());
        }
        //采购总价（含）
        if (null != dto.getPurchase_amount()) {
            whereSql.append(" and mpo.purchase_amount like :purchase_amount ");
            parameter.put("purchase_amount", "%" + dto.getPurchase_amount() + "%");
        }
        //审核人
        if (StringUtils.isNotBlank(dto.getApprove_user_name())) {
            whereSql.append(" and mpo.approve_user_name like :approve_user_name ");
            parameter.put("approve_user_name", "%" + dto.getApprove_user_name() + "%");
        }
        //账期
        if (null != dto.getAccount_period()) {
            whereSql.append(" and mpo.account_period like :account_period ");
            parameter.put("account_period", "%" + dto.getAccount_period() + "%");
        }
        //转采日期
        if (!CollectionUtils.isEmpty(dto.getCreatedTime()) && dto.getCreatedTime().size() >= 2) {
            whereSql.append(" and mpo.createdTime between :startTime and :endTime ");
            parameter.put("startTime", dto.getCreatedTime().get(0));
            parameter.put("endTime", dto.getCreatedTime().get(1));
        }
        //审核日期
        if (!CollectionUtils.isEmpty(dto.getApprove_time()) && dto.getApprove_time().size() >= 2) {
            whereSql.append(" and mpo.approve_time between :approveStartTime and :approveEndTime ");
            parameter.put("approveStartTime", dto.getApprove_time().get(0));
            parameter.put("approveEndTime", dto.getApprove_time().get(1));
        }
        //收票金额大于0
        if (null != dto.getInvoice_price() && dto.getInvoice_price().compareTo(BigDecimal.ZERO) == 0) {
            whereSql.append(" and mpo.invoice_price > 0 ");
        }
        countSql.append(whereSql);
        listSql.append(whereSql);
        listSql.append(" order by mpo.createdTime desc");
        listSql.append(" limit " + dto.getPageIndex() * dto.getPageSize() + ", " + dto.getPageSize());
        log.info("------------------------转采管理-转采客户订单商品列表分页查询/转采管理-采购商品历史列表分页查询 transferOrderGoods listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(listSql.toString(), parameter);
        Integer count = 0;
        try {
            count = jdbcTemplate.queryForObject(countSql.toString(), parameter, Integer.class);
        } catch (DataAccessException e) {
            e.printStackTrace();
        }
        //构建结果集
        BoResultFormat.resultFormat(resultList, ModelConst.T_MEMBER_PURCHASE_ORDER);
        BOList bOList = new BOList();
        bOList.setData(resultList);
        bOList.setTotal(count);
        bOList.setSchemaCode(ModelConst.T_MEMBER_PURCHASE_ORDER);
        return SingleResponse.of(bOList);
    }

    /**
     * 转采管理-采购订单-审核通过
     *
     * @param dto
     * @return
     */
    @Path("applyApproved")
    @POST
    @Operation(summary = "转采管理-采购订单-审核通过", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse applyApproved(@Parameter MemberPurchaseOrderDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID集合必填");
        }
        //TODO 判断当前用户是否为“平台采购员”
        return transferOrderService.approvePurchaseOrder(dto.getIds());
    }

    /**
     * 转采管理-采购订单-驳回
     *
     * @param dto
     * @return
     */
    @Path("applyReject")
    @POST
    @Operation(summary = "转采管理-采购订单-驳回", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse<Boolean> applyReject(@Parameter MemberPurchaseOrderDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID集合必填");
        }
        //TODO 判断当前用户是否为“平台采购员”
        Boolean flag = transferOrderService.disapprovePurchaseOrder(dto.getIds());
        return SingleResponse.of(flag);
    }

    /**
     * 转采管理-采购订单-申请付款列表-提交申请付款
     *
     * @param dto
     * @return
     */
    @Path("applyPayment")
    @POST
    @Operation(summary = "转采管理-采购订单-申请付款列表-提交申请付款", tags = CUSTOM_SERVICE, description = "purchase_amount、payment_amount、sale_amount必填")
    public SingleResponse<BO> applyPayment(@Parameter PurchaseRequestPaymentDto dto) {
        if (null == dto || CollectionUtils.isEmpty(dto.getPaymentDetails())) {
            return SingleResponse.buildFailure("-1", "采购单，采购付款明细必填");
        }
        return transferOrderService.savePurchaseRequestPayment(dto);
    }

    /**
     * 转采管理-采购订单-采购收票-提交收票单
     *
     * @param dto
     * @return
     */
    @Path("savePurchaseOrder")
    @POST
    @Operation(summary = "转采管理-采购订单-提交收票单", tags = CUSTOM_SERVICE, description = "dto、dto.invoice_amount、dto.purchaseInvoiceDetails必填")
    public SingleResponse<BO> savePurchaseOrder(@Parameter PurchaseInvoiceDto dto) {
        return transferOrderService.submitPurchaseOrder(dto);
    }

    /**
     * 转采管理-采购订单-修改付款方式
     *
     * @param dto
     * @return
     */
    @Path("updatePaymentWay")
    @POST
    @Operation(summary = "转采管理-采购订单-修改付款方式", tags = CUSTOM_SERVICE, description = "ids、payment_id、payment_name必填")
    public SingleResponse<BO> updatePaymentWay(@Parameter MemberPurchaseOrderDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "采购申请支付ID必填");
        }
        if (StringUtils.isBlank(dto.getPayment_id())) {
            return SingleResponse.buildFailure("-1", "付款方式ID必填");
        }
        if (StringUtils.isBlank(dto.getPayment_name())) {
            return SingleResponse.buildFailure("-1", "付款方式名称必填");
        }
        List<Map<String, Object>> orderParams = new ArrayList<>();
        for (String id : dto.getIds()) {
            Map<String, Object> orderParam = new HashMap<>();
            orderParam.put("id", id);
            orderParam.put("payment_id", dto.getPayment_id());
            orderParam.put("payment_name", dto.getPayment_name());
            orderParams.add(orderParam);
        }
        return BoServiceUtils.updateMainBo(ModelConst.T_MEMBER_PURCHASE_ORDER, orderParams);
    }

    /**
     * 转采管理-采购订单-修改订单
     *
     * @param dto
     * @return
     */
    @Path("updatePurchaseOrder")
    @POST
    @Operation(summary = "转采管理-采购订单-修改订单", tags = CUSTOM_SERVICE, description = "dto、memberPurchaseOrderGoods必填")
    public SingleResponse<BO> updatePurchaseOrder(@Parameter MemberPurchaseOrderDto dto) {
        if (null == dto) {
            return SingleResponse.buildFailure("-1", "转采订单必填");
        }
        if (CollectionUtils.isEmpty(dto.getMemberPurchaseOrderGoods())) {
            return SingleResponse.buildFailure("-1", "转采订单商品集合必填");
        }
        SingleResponse<BO> result = transferOrderService.editPurchaseOrder(dto);
        return result;
    }

    /**
     * 转采管理-采购订单-修改付款方式
     *
     * @param dtos
     * @return
     */
    @Path("updateContractStatus")
    @POST
    @Operation(summary = "转采管理-采购订单-修改合同状态", tags = CUSTOM_SERVICE, description = "id, contract_or_sent必填：eg:[{\"id\":\"10672\",\"contract_or_sent\":false}]")
    public SingleResponse<BO> updateContractStatus(@Parameter List<MemberPurchaseOrderDto> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return SingleResponse.buildFailure("-1", "会员采购订单必填");
        }
        List<Map<String, Object>> orderParams = new ArrayList<>();
        for (MemberPurchaseOrderDto dto : dtos) {
            if (StringUtils.isBlank(dto.getId())) {
                return SingleResponse.buildFailure("-1", "采购申请支付ID必填");
            }
            if (null == dto.getContract_or_sent()) {
                return SingleResponse.buildFailure("-1", "合同是否已发必填");
            }
            Map<String, Object> orderParam = new HashMap<>();
            orderParam.put("id", dto.getId());
            orderParam.put("contract_or_sent", dto.getContract_or_sent() ? true : false);
            orderParams.add(orderParam);
        }
        return BoServiceUtils.updateMainBo(ModelConst.T_MEMBER_PURCHASE_ORDER, orderParams);
    }

    /**
     * 转采管理-采购订单-取消审核
     *
     * @param dto
     * @return
     */
    @Path("cancelCheck")
    @POST
    @Operation(summary = "转采管理-采购订单-取消审核", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse<Boolean> cancelCheck(@Parameter MemberPurchaseOrderDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID集合必填");
        }
        return SingleResponse.of(transferOrderService.purchaseReturn(dto.getIds(), 2));
    }

    /**
     * 转采管理-采购订单-采购单作废
     *
     * @param dto
     * @return
     */
    @Path("purchaseCancel")
    @POST
    @Operation(summary = "转采管理-采购订单-采购单作废", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse<Boolean> purchaseCancel(@Parameter MemberPurchaseOrderDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID集合必填");
        }
        return SingleResponse.of(transferOrderService.purchaseReturn(dto.getIds(), 1));
    }

    /**
     * 转采管理-采购订单-不再付款
     *
     * @param dto
     * @return
     */
    @Path("noPayment")
    @POST
    @Operation(summary = "转采管理-采购订单-不再付款", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse<BO> noPayment(@Parameter MemberPurchaseOrderDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID集合必填");
        }
        List<Map<String, Object>> memberPurchaseOrders = JdbcTemplateUtils.builder(ModelConst.T_MEMBER_PURCHASE_ORDER)
                .selectField("*").in("id", dto.getIds()).queryForList();
        List<Map<String, Object>> memberPurchaseOrdersParams = new ArrayList<>();
        for (Map<String, Object> mps : memberPurchaseOrders) {
            if (!mps.get("member_purchase_order_status").equals(MemberPurchaseOrderEnum.PARTIAL.id.toString())) {
                throw new RuntimeException("请选择部分付款的进行操作");
            }
            Map<String, Object> memberPurchaseOrdersParam = new HashMap<>();
            memberPurchaseOrdersParam.put("no_more_payment", true);
            memberPurchaseOrdersParam.put("id", mps.get("id"));
            memberPurchaseOrdersParams.add(memberPurchaseOrdersParam);
        }
        return BoServiceUtils.updateMainBo(ModelConst.T_MEMBER_PURCHASE_ORDER, memberPurchaseOrdersParams);
    }

    /**
     * 转采管理-采购订单商品列表分页查询
     *
     * @param dto
     * @return
     */
    @Path("transferPurchaseOrderGoodsList")
    @POST
    @Operation(summary = "转采管理-采购订单商品列表分页查询", tags = CUSTOM_SERVICE, description = "pageIndex、pageSize必填")
    public SingleResponse<BOList> transferPurchaseOrderGoodsList(@Parameter MemberPurchaseOrderGoodsDto dto) {
        log.info("------------------------转采管理-采购订单商品列表分页查询 transferPurchaseOrderGoodsList Param：{}------------------------", JsonUtils.toJson(dto));
        if (null == dto.getPageIndex() || null == dto.getPageSize()) {
            return SingleResponse.buildFailure("-1", "pageIndex、pageSize必填");
        }
        String mpgTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER_GOODS);
        String mpoTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER);
        String tosTableName = getTableName(ModelConst.T_TRANSFER_ORDER);
        String togTableName = getTableName(ModelConst.T_TRANSFER_ORDER_GOODS);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        StringBuilder countSql = new StringBuilder();
        listSql.append("select case when mpg.cloud_order_goods_id is null or mpg.cloud_order_goods_id='' then tog.cloud_order_goods_id end as cloud_order_goods_id, " +
                "case when mpg.cloud_order_id is null or mpg.cloud_order_id='' then tos.cloud_order_id end as cloud_order_id, mpg.*,mpo.*,tog.*,tos.*  from " + mpgTableName + " mpg " +
                "INNER JOIN " + mpoTableName + " mpo on mpg.member_purchase_order_id = mpo.id " +
                "LEFT JOIN " + togTableName + " tog on tog.id = mpg.transfer_order_goods_id " +
                "LEFT JOIN " + tosTableName + " tos on tos.id = tog.transfer_order_id where mpg.deleted = '0' ");
        countSql.append("select count(*) from " + mpgTableName + " mpg " +
                "INNER JOIN " + mpoTableName + " mpo on mpg.member_purchase_order_id = mpo.id " +
                "LEFT JOIN " + togTableName + " tog on tog.id = mpg.transfer_order_goods_id " +
                "LEFT JOIN " + tosTableName + " tos on tos.id = tog.transfer_order_id where mpg.deleted = '0' ");
        //云平台订单号
        if (StringUtils.isNotBlank(dto.getCloud_order_id())) {
            List<String> ids = StringUtils.stringToListString(dto.getCloud_order_id(), ";");
            whereSql.append(" and tos.cloud_order_id in (:cloud_order_id) ");
            parameter.put("cloud_order_id", ids);
        }
        //云平台订单商品号
        if (StringUtils.isNotBlank(dto.getCloud_order_goods_id())) {
            List<String> ids = StringUtils.stringToListString(dto.getCloud_order_goods_id(), ";");
            whereSql.append(" and tog.cloud_order_goods_id in (:cloud_order_goods_id) ");
            parameter.put("cloud_order_goods_id", ids);
        }
        //采购P单
//        if (StringUtils.isNotBlank(dto.getPo_code())) {
//            List<String> poCodes = StringUtils.stringToListString(dto.getPo_code(), ";");
//            whereSql.append(" and mpo.po_code in (:po_code) ");
//            parameter.put("po_code", poCodes);
//        }

        //采购P单 member_purchase_order_id ：模型字段拖拽限制，使用 member_purchase_order_id
        if (StringUtils.isNotBlank(dto.getMember_purchase_order_id())) {
            List<String> memberPurchaseOrderIds = StringUtils.stringToListString(dto.getMember_purchase_order_id(), ";");
            whereSql.append(" and mpo.po_code in (:member_purchase_order_id) ");
            parameter.put("member_purchase_order_id", memberPurchaseOrderIds);
        }
        //采购员
        if (StringUtils.isNotBlank(dto.getBuyer())) {
            whereSql.append(" and mpo.buyer like :buyer ");
            parameter.put("buyer", "%" + dto.getBuyer() + "%");
        }
        //供应商
        if (StringUtils.isNotBlank(dto.getVendor_name())) {
            whereSql.append(" and mpo.vendor_name like :vendor_name ");
            parameter.put("vendor_name", "%" + dto.getVendor_name() + "%");
        }
        //采购单付款状态
        if (StringUtils.isNotBlank(dto.getMember_purchase_order_status())) {
            whereSql.append(" and mpo.member_purchase_order_status = :member_purchase_order_status ");
            parameter.put("member_purchase_order_status", dto.getMember_purchase_goods_status());
        }
        //采购单收票状态
        if (StringUtils.isNotBlank(dto.getInvoice_status())) {
            whereSql.append(" and mpo.invoice_status = :invoice_status ");
            parameter.put("invoice_status", dto.getInvoice_status());
        }
        //付款方式
        if (StringUtils.isNotBlank(dto.getPayment_id())) {
            whereSql.append(" and mpo.payment_id = :payment_id ");
            parameter.put("payment_id", dto.getPayment_id());
        }
        //发票类型
        if (StringUtils.isNotBlank(dto.getInvoice_type())) {
            whereSql.append(" and mpo.invoice_type = :invoice_type ");
            parameter.put("invoice_type", dto.getInvoice_type());
        }
        //商品状态
        if (StringUtils.isNotBlank(dto.getMember_purchase_goods_status())) {
            whereSql.append(" and mpg.member_purchase_goods_status = :member_purchase_goods_status ");
            parameter.put("member_purchase_goods_status", dto.getMember_purchase_goods_status());
        }
        //商品名称
        if (null != dto.getName()) {
            whereSql.append(" and tog.name like :name ");
            parameter.put("name", "%" + dto.getName() + "%");
        }
        //采购总价（含）
        if (null != dto.getPurchase_amount()) {
            whereSql.append(" and mpo.purchase_amount like :purchase_amount ");
            parameter.put("purchase_amount", "%" + dto.getPurchase_amount() + "%");
        }
        //品牌
        if (StringUtils.isNotBlank(dto.getBrand())) {
            whereSql.append(" and tog.brand like :brand ");
            parameter.put("brand", "%" + dto.getBrand() + "%");
        }
        //型号
        if (StringUtils.isNotBlank(dto.getModel())) {
            whereSql.append(" and tog.model like :model ");
            parameter.put("model", "%" + dto.getModel() + "%");
        }
        //物流单号
        if (StringUtils.isNotBlank(dto.getLogistics_number())) {
            whereSql.append(" and tog.name like :name ");
            parameter.put("name", "%" + dto.getName() + "%");
        }
        //供应商回复交期
        if (!CollectionUtils.isEmpty(dto.getDelivery_memo()) && dto.getDelivery_memo().size() >= 2) {
            whereSql.append(" and mpg.delivery_memo between :deliveryStartTime and :deliveryEndTime ");
            parameter.put("deliveryStartTime", dto.getDelivery_memo().get(0));
            parameter.put("deliveryEndTime", dto.getDelivery_memo().get(1));
        }
        //采购单日期
        if (!CollectionUtils.isEmpty(dto.getCreatedTime()) && dto.getCreatedTime().size() >= 2) {
            whereSql.append(" and tog.createdTime between :startTime and :endTime ");
            parameter.put("startTime", dto.getCreatedTime().get(0));
            parameter.put("endTime", dto.getCreatedTime().get(1));
        }
        //是否退货
        if (null != dto.getIs_return() && dto.getIs_return()) {
            whereSql.append(" and mpo.is_rp = true ");
        }
        countSql.append(whereSql);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        listSql.append(" limit " + dto.getPageIndex() * dto.getPageSize() + ", " + dto.getPageSize());
        log.info("------------------------转采管理-采购订单商品列表分页查询 transferPurchaseOrderGoodsList listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(listSql.toString(), parameter);
        Integer count = 0;
        try {
            count = jdbcTemplate.queryForObject(countSql.toString(), parameter, Integer.class);
        } catch (DataAccessException e) {
            e.printStackTrace();
        }
        //构建结果集
        BoResultFormat.resultFormat(resultList, ModelConst.T_MEMBER_PURCHASE_ORDER_GOODS);
        BOList bOList = new BOList();
        bOList.setData(resultList);
        bOList.setTotal(count);
        bOList.setSchemaCode(ModelConst.T_MEMBER_PURCHASE_ORDER_GOODS);
        return SingleResponse.of(bOList);
    }

    /**
     * 转采管理-采购订单商品-申请退货
     *
     * @param dto
     * @return
     */
    @Path("applyReturn")
    @POST
    @Operation(summary = "转采管理-采购订单商品-申请退货", tags = CUSTOM_SERVICE, description = "dto、id、dto.memberPurchaseOrderGoods必填")
    public SingleResponse<BO> applyReturn(@Parameter MemberPurchaseOrderDto dto) {
        if (null == dto) {
            return SingleResponse.buildFailure("-1", "会员采购订单必填");
        }
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID必填");
        }
        if (CollectionUtils.isEmpty(dto.getMemberPurchaseOrderGoods())) {
            return SingleResponse.buildFailure("-1", "会员采购订单商品必填");
        }
        return transferOrderService.createMemberPurchaseOrderRefund(dto);
    }

    /**
     * 转采管理-采购订单商品-修改备注
     *
     * @param dto
     * @return
     */
    @Path("updatePurchaseMemo")
    @POST
    @Operation(summary = "转采管理-采购订单商品-修改备注", tags = CUSTOM_SERVICE, description = "id、memo必填")
    public SingleResponse<BO> updatePurchaseMemo(@Parameter MemberPurchaseOrderDto dto) {
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID必填");
        }
        if (StringUtils.isBlank(dto.getMemo())) {
            return SingleResponse.buildFailure("-1", "备注必填");
        }
        Map<String, Object> param = new HashMap<>();
        param.put("id", dto.getId());
        param.put("memo", dto.getMemo());
        return BoServiceUtils.updateMainBo(ModelConst.T_MEMBER_PURCHASE_ORDER, param);
    }

    /**
     * 转采管理-采购订单商品-维护物流
     *
     * @param dto
     * @return
     */
    @Path("updatePurchaseLogistics")
    @POST
    @Operation(summary = "转采管理-采购订单商品-维护物流", tags = CUSTOM_SERVICE, description = "id、delivery_number必填，" +
            "logistics_name、logistics_number、maintenance_logistics_time、maintenance_logistics_user选填")
    public SingleResponse<BO> updatePurchaseLogistics(@Parameter MemberPurchaseOrderGoodsDto dto) {
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "会员采购订单ID必填");
        }
        log.info("-------" + dto.getDelivery_number().compareTo(BigDecimal.ZERO));
        if (null == dto.getDelivery_number() || dto.getDelivery_number().compareTo(BigDecimal.ZERO) < 1) {
            return SingleResponse.buildFailure("-1", "发货数量必填,并大于0");
        }
        Map<String, Object> param = new HashMap<>();
        param.put("id", dto.getId());
        param.put("delivery_number", dto.getDelivery_number());
        param.put("logistics_name", dto.getLogistics_name());
        param.put("logistics_number", dto.getLogistics_number());
        param.put("delivery_memo", dto.getDelivery_memo());
        param.put("maintenance_logistics_time", dto.getMaintenance_logistics_time());
        param.put("maintenance_logistics_user", null == dto.getMaintenance_logistics_user() ? getSelectorFormat() : dto.getMaintenance_logistics_user().get(0));
        return BoServiceUtils.updateMainBo(ModelConst.T_MEMBER_PURCHASE_ORDER_GOODS, param);
    }

    /**
     * 转采管理-采购付款-审核
     *
     * @param dto
     * @return
     */
    @Path("approvePayment")
    @POST
    @Operation(summary = "转采管理-采购付款-审核", tags = CUSTOM_SERVICE, description = "ids、is_pass必填,approve_comments非必填")
    public SingleResponse<Boolean> approvePayment(@Parameter PurchaseRequestPaymentDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "采购申请支付ID必填");
        }
        if (null == dto.getIs_pass()) {
            return SingleResponse.buildFailure("-1", "审核是否通过必填");
        }
        return SingleResponse.of(transferOrderService.approvePurchaseRequestPayment(dto));
    }

    /**
     * 转采管理-采购付款-作废
     *
     * @param dto
     * @return
     */
    @Path("disusedPayment")
    @POST
    @Operation(summary = "转采管理-采购付款-作废", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse<Boolean> disusedPayment(@Parameter PurchaseRequestPaymentDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "采购申请支付ID必填");
        }
        return SingleResponse.of(transferOrderService.abandonPayment(dto.getIds()));
    }

    /**
     * 转采管理-采购收票列表分页查询
     *
     * @param dto
     * @return
     */
    @Path("purchaseInvoiceList")
    @POST
    @Operation(summary = "转采管理-采购订单商品列表分页查询", tags = CUSTOM_SERVICE, description = "pageIndex、pageSize必填")
    public SingleResponse<BOList> purchaseInvoiceList(@Parameter PurchasePaymentInvoiceDto dto) {
        log.info("------------------------转采管理-采购订单商品列表分页查询 purchaseInvoiceList Param：{}------------------------", JsonUtils.toJson(dto));
        if (null == dto.getPageIndex() || null == dto.getPageSize()) {
            return SingleResponse.buildFailure("-1", "pageIndex、pageSize必填");
        }
        String piTableName = getTableName(ModelConst.T_PURCHASE_INVOICE);
        String pidTableName = getTableName(ModelConst.T_PURCHASE_INVOICE_DETAIL);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        StringBuilder countSql = new StringBuilder();
        listSql.append("SELECT pi.*, GROUP_CONCAT(pid.invoice_number) invoice_number\n" +
                " FROM " + piTableName + " pi\n" +
                " LEFT JOIN " + pidTableName + " pid ON pid.purchase_invoice_id = pi.id\n" +
                " WHERE pi.deleted = false");
        countSql.append("SELECT count(*) \n" +
                " FROM " + piTableName + " pi\n" +
                " LEFT JOIN " + pidTableName + " pid ON pid.purchase_invoice_id = pi.id\n" +
                " WHERE pi.deleted = false");
        //采购P单
        if (StringUtils.isNotBlank(dto.getPo_code())) {
            List<String> poCodes = StringUtils.stringToListString(dto.getPo_code(), ";");
            whereSql.append(" and pi.po_code in (:po_code) ");
            parameter.put("po_code", poCodes);
        }
        //发票抬头
        if (StringUtils.isNotBlank(dto.getTitle())) {
            whereSql.append(" and pi.title like :title ");
            parameter.put("title", dto.getTitle());
        }
        //申请人
        if (StringUtils.isNotBlank(dto.getApplicant())) {
            whereSql.append(" and pi.applicant like :applicant ");
            parameter.put("applicant", dto.getApplicant());
        }
        //平台组织名称
        if (StringUtils.isNotBlank(dto.getPlatform_name())) {
            whereSql.append(" and pi.platform_name like :platform_name ");
            parameter.put("platform_name", dto.getPlatform_name());
        }
        //采购收票状态
        if (StringUtils.isNotBlank(dto.getPurchase_invoice_status())) {
            whereSql.append(" and pi.purchase_invoice_status = :purchase_invoice_status ");
            parameter.put("purchase_invoice_status", dto.getPurchase_invoice_status());
        }
        //采购收票种类
        if (StringUtils.isNotBlank(dto.getInvoice_type())) {
            whereSql.append(" and pi.invoice_type = :invoice_type ");
            parameter.put("invoice_type", dto.getInvoice_type());
        }
        //发票号码
        if (StringUtils.isNotBlank(dto.getInvoice_number())) {
            whereSql.append(" and pid.invoice_number like :invoice_number ");
            parameter.put("invoice_type", dto.getInvoice_type());
        }
        //收票申请日期
        if (!CollectionUtils.isEmpty(dto.getCreatedTime()) && dto.getCreatedTime().size() >= 2) {
            whereSql.append(" and tog.createdTime between :startTime and :endTime ");
            parameter.put("startTime", dto.getCreatedTime().get(0));
            parameter.put("endTime", dto.getCreatedTime().get(1));
        }
        countSql.append(whereSql);
        listSql.append(whereSql);
        listSql.append(" GROUP BY pi.id limit " + dto.getPageIndex() * dto.getPageSize() + ", " + dto.getPageSize());
        log.info("------------------------转采管理-采购订单商品列表分页查询 purchaseInvoiceList listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(listSql.toString(), parameter);
        Integer count = 0;
        try {
            count = jdbcTemplate.queryForObject(countSql.toString(), parameter, Integer.class);
        } catch (DataAccessException e) {
            e.printStackTrace();
        }
        //构建结果集
        BoResultFormat.resultFormat(resultList, ModelConst.T_PURCHASE_INVOICE);
        BOList bOList = new BOList();
        bOList.setData(resultList);
        bOList.setTotal(count);
        bOList.setSchemaCode(ModelConst.T_PURCHASE_INVOICE);
        return SingleResponse.of(bOList);
    }

    /**
     * 转采管理-采购收票-提交财务/转采管理-采购收票-取消收票
     *
     * @param dto
     * @return
     */
    @Path("cancelOrConfirmInvoice")
    @POST
    @Operation(summary = "转采管理-采购收票-提交财务/转采管理-采购收票-取消收票", tags = CUSTOM_SERVICE, description = "ids、type必填，取消收票为1;提交财务为4")
    public SingleResponse<Boolean> cancelOrConfirmInvoice(@Parameter PurchaseInvoiceDto dto) {
        return SingleResponse.of(transferOrderService.invoiceCancelOrConfirm(dto.getIds(), dto.getType(), null));
    }

    /**
     * 转采管理-采购收票-修改发票
     *
     * @param dto
     * @return
     */
    @Path("updateInvoice")
    @POST
    @Operation(summary = "转采管理-采购收票-修改发票-采购收票修改", tags = CUSTOM_SERVICE, description = "id、" +
            "purchaseInvoiceDetails.id、purchaseInvoiceDetails.invoice_number、purchaseInvoiceDetails.invoice_time")
    public SingleResponse<BO> updateInvoice(@Parameter PurchaseInvoiceDto dto) {
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "采购收票ID必填");
        }
        if (CollectionUtils.isEmpty(dto.getPurchaseInvoiceDetails())) {
            return SingleResponse.buildFailure("-1", "采购收票明细必填");
        }
        for (PurchaseInvoiceDetailDto purchaseInvoiceDetail : dto.getPurchaseInvoiceDetails()) {
            if (StringUtils.isBlank(purchaseInvoiceDetail.getId())) {
                return SingleResponse.buildFailure("-1", "采购收票明细ID必填");
            }
            if (StringUtils.isBlank(purchaseInvoiceDetail.getInvoice_number())) {
                return SingleResponse.buildFailure("-1", "采购收票明细发票号码必填");
            }
            if (StringUtils.isBlank(purchaseInvoiceDetail.getInvoice_time())) {
                return SingleResponse.buildFailure("-1", "采购收票明细采购收票时间必填");
            }
        }
        return transferOrderService.updatePurchaseInvoice(dto);
    }

    /**
     * 转采管理-采购订单-修改订单-通过采购订单ID查询采购订单商品数据
     *
     * @param dto
     * @return
     */
    @Path("purchaseGoodsFindByPurchaseId")
    @POST
    @Operation(summary = "转采管理-采购订单-修改订单-通过采购订单ID查询采购订单商品数据", tags = CUSTOM_SERVICE, description = "id必填")
    public SingleResponse<BO> purchaseGoodsFindByPurchaseId(@Parameter MemberPurchaseOrderDto dto) {
        return transferOrderService.purchaseGoodsFindByPurchase(dto);
    }

    /**
     * 转采管理-转采客户订单-导出列表
     *
     * @param bo
     * @return
     */
    @Path("exporOrderCustomer")
    @POST
    @Operation(summary = "转采管理-转采客户订单-导出列表", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporOrderCustomer(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        SingleResponse<BOList> singleResponse = BoQueryUtils.Builder(ModelConst.T_TRANSFER_ORDER)
                .condition()
                .in("id", ids)
                .End().listBO();
        if (!singleResponse.isSuccess()) {
            return singleResponse;
        }
        List<Map<String, Object>> data = singleResponse.getData().getData();

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"id\":\"id\",\"time\":\"createdTime\",\"total\":\"total\",\"amount\":\"amount\",\"receiver\":\"receiver\",\"phone\":\"phone\",\"postal\":\"postal\",\"address\":\"address\",\"memberName\":\"user_name\",\"orgName\":\"organization_name\",\"cloudOrderId\":\"cloud_order_id\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            Map<String, Object> mf = new HashMap<>();
            mf.put("id", m.get("id"));
            mf.put("time", m.get("createdTime"));
            mf.put("total", m.get("total") == null ? null : String.valueOf(new BigDecimal(m.get("total").toString()).doubleValue()));
            mf.put("amount", m.get("amount") == null ? null : String.valueOf(new BigDecimal(m.get("amount").toString()).doubleValue()));
            mf.put("receiver", m.get("receiver"));
            mf.put("phone", m.get("phone"));
            mf.put("postal", m.get("postal"));
            mf.put("address", m.get("address"));
            mf.put("memberName", m.get("user_name"));
            mf.put("orgName", m.get("organization_name"));
            mf.put("cloudOrderId", m.get("cloud_order_id"));
            return mf;
        }).collect(Collectors.toList());


        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-转采客户订单-导出参数 exporOrderCustomer:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("transfer_order_report", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }


    /**
     * 转采管理-转采客户订单商品-导出列表
     *
     * @param bo
     * @return
     */
    @Path("exporTransferOrderGoodsReport")
    @POST
    @Operation(summary = "转采管理-转采客户订单商品-导出列表", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporTransferOrderGoodsReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        SingleResponse<BOList> singleResponse = BoQueryUtils.Builder(ModelConst.T_TRANSFER_ORDER_GOODS)
                .condition()
                .in("id", ids)
                .End().listBO();
        if (!singleResponse.isSuccess()) {
            return singleResponse;
        }
        List<Map<String, Object>> data = singleResponse.getData().getData();

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"time\":\"createdTime\",\"brand\":\"brand\",\"name\":\"name\",\"model\":\"model\",\"spec\":\"spec\",\"sku\":\"sku\",\"memo\":\"memo\",\"unit\":\"unit\",\"delivery\":\"delivery\",\"num\":\"num\",\"taxRate\":\"tax_rate\",\"price\":\"price\",\"amount\":\"amount\",\"status\":\"transfer_order_goods_status\",\"cloudOrderGoodsId\":\"cloud_order_goods_id\",\"vendorName\":\"vendor_name\",\"transferOrderId\":\"transfer_order_id\",\"cloudOrderId\":\"cloud_order_id\",\"customerName\":\"user_name\",\"inquiryId\":\"inquiry_id\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            Map<String, Object> mf = new HashMap<>();
            mf.put("time", m.get("createdTime"));
            mf.put("brand", m.get("brand"));
            mf.put("name", m.get("name"));
            mf.put("model", m.get("model"));
            mf.put("spec", m.get("spec"));
            mf.put("sku", m.get("sku"));
            mf.put("memo", m.get("memo"));
            mf.put("unit", m.get("unit"));
            mf.put("delivery", m.get("delivery").toString());
            mf.put("num", m.get("num") == null ? null : String.valueOf(new BigDecimal(m.get("num").toString()).doubleValue()));
            mf.put("taxRate", m.get("tax_rate") == null ? null : String.valueOf(new BigDecimal(m.get("tax_rate").toString()).doubleValue()));
            mf.put("price", m.get("price") == null ? null : new BigDecimal(m.get("price").toString()).doubleValue());
            mf.put("amount", m.get("amount") == null ? null : String.valueOf(new BigDecimal(m.get("amount").toString()).doubleValue()));
            mf.put("status", m.get("transfer_order_goods_status"));
            mf.put("cloudOrderGoodsId", m.get("cloud_order_goods_id"));
            mf.put("vendorName", m.get("vendor_name"));
            mf.put("transferOrderId", m.get("transfer_order_id"));
            mf.put("cloudOrderId", m.get("cloud_order_id"));
            mf.put("customerName", m.get("user_name"));
            mf.put("inquiryId", m.get("inquiry_id"));
            return mf;
        }).collect(Collectors.toList());


        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-转采客户订单商品-导出参数 exporTransferOrderGoodsReport :reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("transfer_order_goods_report", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }

    /**
     * 转采管理-采购订单-导出列表
     *
     * @param bo
     * @return
     */
    @Path("exporPurchaseOrderReport")
    @POST
    @Operation(summary = "转采管理-采购订单-导出列表", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporPurchaseOrderReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        SingleResponse<BOList> singleResponse = BoQueryUtils.Builder(ModelConst.T_MEMBER_PURCHASE_ORDER)
                .condition()
                .in("id", ids)
                .End().listBO();
        if (!singleResponse.isSuccess()) {
            return singleResponse;
        }
        List<Map<String, Object>> data = singleResponse.getData().getData();

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"id\":\"id\",\"poCode\":\"po_code\",\"status\":\"member_purchase_order_status\",\"invoiceStatus\":\"invoice_status\",\"purchaseAmount\":\"purchase_amount\",\"noPaymentAmount\":\"no_payment_amount\",\"paymentName\":\"payment_name\",\"invoiceRate\":\"invoice_rate\",\"transferVendorName\":\"vendor_name\",\"memo\":\"memo\",\"time\":\"createdTime\",\"buyer\":\"buyer\",\"cloudOrderIds\":\"cloud_order_ids\",\"customerName\":\"customer_name\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            Map<String, Object> mf = new HashMap<>();

            mf.put("id", m.get("id"));
            mf.put("poCode", m.get("po_code"));
            mf.put("status", m.get("member_purchase_order_status"));
            mf.put("invoiceStatus", m.get("invoice_status"));
            mf.put("purchaseAmount", m.get("purchase_amount") == null ? null : new BigDecimal(m.get("purchase_amount").toString()).doubleValue());
            mf.put("noPaymentAmount", m.get("no_payment_amount") == null ? null : new BigDecimal(m.get("no_payment_amount").toString()).doubleValue());
            mf.put("paymentName", m.get("payment_name"));
            mf.put("invoiceRate", m.get("invoice_rate") == null ? null : new BigDecimal(m.get("invoice_rate").toString()).doubleValue());
            mf.put("transferVendorName", m.get("vendor_name"));
            mf.put("memo", m.get("memo"));
            mf.put("time", m.get("createdTime"));
            mf.put("buyer", m.get("buyer"));
            mf.put("cloudOrderIds", m.get("cloud_order_ids"));
            mf.put("customerName", m.get("customer_name"));
            mf.put("refundReason", m.get("refund_reason"));
            //退款单
            if (m.get("relation_purchase_id") != null) {
                SingleResponse<BOList> rp = BoQueryUtils.Builder(ModelConst.T_MEMBER_PURCHASE_ORDER)
                        .condition()
                        .eq("id", m.get("relation_purchase_id"))
                        .End().listBO();
                if (rp.isSuccess() && rp.getData().getData() != null) {
                    mf.put("rpCode", rp.getData().getData().get(0).get("po_code"));
                }
            }

            return mf;
        }).collect(Collectors.toList());


        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购订单-导出参数 exporPurchaseOrderReport:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("purchase_order_report", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }

    /**
     * 转采管理-采购订单-打印采购单
     *
     * @param bo
     * @return
     */
    @Path("printPurchaseOrderReport")
    @POST
    @Operation(summary = "转采管理-采购订单-打印采购单", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse printPurchaseOrderReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        String mpgTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER_GOODS);
        String mpoTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER);
        String togTableName = getTableName(ModelConst.T_TRANSFER_ORDER_GOODS);
        String tosTableName = getTableName(ModelConst.T_TRANSFER_ORDER);
        String ttvTableName = getTableName(ModelConst.T_TRANSFER_VENDOR);
        String tpaTableName = getTableName(ModelConst.T_PURCHASING_AGENT);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append(" SELECT mpo.po_code poCode,mpo.id id,mpo.cloud_order_ids cloudOrderIds,mpo.createdTime time," +
                " mpo.payment_name paymentName,mpo.invoice_rate invoiceRate,ttv.company_name vendorName,ttv.contact transferVendorContacts," +
                " ttv.mobile transferVendorMobile,ttv.email transferVendorEmail,tog.cloud_order_id cloudOrderId,tog.`name` ," +
                " tog.brand ,tog.model ,tog.spec ,tog.unit ,tos.receiver ,tos.address ,tos.phone ,mpg.num,mpg.price,mpg.amount," +
                " mpg.pretax_amount preAmount,mpg.memo,mpg.delivery_time deliveryTime,tpa.`name` fullName FROM " + mpgTableName + " mpg " +
                " INNER JOIN " + mpoTableName + " mpo ON mpg.member_purchase_order_id = mpo.id " +
                " LEFT JOIN " + togTableName + " tog ON tog.id = mpg.transfer_order_goods_id " +
                " LEFT JOIN " + tosTableName + " tos ON tos.id = tog.transfer_order_id " +
                " LEFT JOIN " + ttvTableName + " ttv ON  mpo.vendor_id = ttv.id  " +
                " LEFT JOIN " + tpaTableName + " tpa ON  mpo.buyer_id = tpa.id WHERE mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" AND mpo.id IN (:ids) ");
        parameter.put("ids", ids);
        listSql.append(whereSql);
        listSql.append(" ORDER BY mpg.createdTime DESC");
        log.info("------------------------转采管理-采购订单-打印采购单 printPurchaseOrderReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"fullName\":\"full_name\",\"id\":\"id\",\"brand\":\"brand\",\"name\":\"name\",\"unit\":\"unit\",\"amount\":\"amount\",\"time\":\"createdTime\",\"num\":\"num\",\"price\":\"price\",\"poCode\":\"po_code\",\"cloudOrderIds\":\"cloud_order_ids\",\"vendorName\":\"vendor_name\",\"transferVendorContacts\":\"transfer_order_ids\",\"transferVendorMobile\":\"phone\",\"transferVendorEmail\":\"email\",\"mobile\":\"phone\",\"email\":\"email\",\"cloudOrderId\":\"cloud_order_id\",\"modelAndSpec\":\"model\",\"invoiceRate\":\"invoice_rate\",\"memo\":\"memo\",\"deliveryTime\":\"delivery_time\",\"receiveMessage\":\"receiver\",\"paymentName\":\"payment_name\",\"preAmount\":\"pre_amount\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {

            if (m.get("deliveryTime") != null) {
                m.put("deliveryTime", DateUtils.format2DateStr2((Date) m.get("deliveryTime")));
            }
            if (m.get("time") != null) {
                m.put("time", DateUtils.format2DateStr2((Date) m.get("time")));
            }
            m.put("modelAndSpec", m.get("model") + "/" + m.get("spec"));
            m.put("receiveMessage", m.get("receiver") + "/" + m.get("address") + "/" + m.get("phone"));

            if (m.get("num") != null) {
                m.put("num", new BigDecimal(m.get("num").toString()).doubleValue());
            }
            if (m.get("amount") != null) {
                m.put("amount", new BigDecimal(m.get("amount").toString()).doubleValue());
            }
            if (m.get("price") != null) {
                m.put("price", new BigDecimal(m.get("price").toString()).doubleValue());
            }
            if (m.get("preAmount") != null) {
                m.put("preAmount", new BigDecimal(m.get("preAmount").toString()).doubleValue());
            }
            if (m.get("invoiceRate") != null) {
                m.put("invoiceRate", new BigDecimal(m.get("invoiceRate").toString()).doubleValue());
            }

            return m;
        }).collect(Collectors.toList());

        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购订单-打印采购单:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("purchase_order_print_report", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }


    /**
     * 转采管理-采购订单商品-导出列表
     *
     * @param bo
     * @return
     */
    @Path("exporPurchaseOrderGoodsReport")
    @POST
    @Operation(summary = "转采管理-采购订单商品-导出列表", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporPurchaseOrderGoodsReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        String mpgTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER_GOODS);
        String mpoTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER);
        String tosTableName = getTableName(ModelConst.T_TRANSFER_ORDER);
        String togTableName = getTableName(ModelConst.T_TRANSFER_ORDER_GOODS);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append(" SELECT mpg.createdTime time,mpg.memo,mpg.delivery_time deliveryTime,mpg.num,mpg.price,mpg.amount,mpg.vendor_name vendorName, " +
                " mpg.payment_id,mpg.gross_profit_rate grossProfitRate,tog.cloud_order_id cloudOrderId,tog.cloud_order_goods_id cloudOrderGoodsId, " +
                " tog.brand,tog.`name`,tog.model,tog.spec,tog.unit,tog.price transferPrice,tog.num transferNum,tog.pre_amount transferAmount, " +
                " tog.vendor_name transferVendorName,tog.transfer_order_goods_status cloudOrderGoodsStatus,tos.account_period accountPeriod, " +
                " tos.organization_name orgName,mop.member_purchase_order_status orderStatus,mop.invoice_status invoiceStatus,mop.po_code purchaseCode, " +
                " mop.purchase_amount purchaseAmount,mop.payment_name paymentName,mop.sale_amount purchaseOrderSaleAmount,mop.buyer,mop.invoice_rate, " +
                " mop.invoice_type invoiceType,mop.platform_name platformName,mop.id purchase_id  FROM " + mpgTableName + " AS mpg " +
                " INNER JOIN " + mpoTableName + " AS mop on mpg.member_purchase_order_id = mop.id " +
                " LEFT JOIN " + togTableName + " AS tog on tog.id = mpg.transfer_order_goods_id " +
                " LEFT JOIN " + tosTableName + " AS tos on tos.id = tog.transfer_order_id where mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" and mpg.id in (:ids) ");
        parameter.put("ids", ids);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        log.info("------------------------转采管理-采购订单商品-导出列表 exporPurchaseOrderGoodsReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }
        String exportField = "{\"time\":\"createdTime\",\"brand\":\"brand\",\"name\":\"name\",\"model\":\"model\",\"spec\":\"spec\",\"memo\":\"memo\",\"unit\":\"unit\",\"num\":\"num\",\"price\":\"price\",\"amount\":\"amount\",\"vendorName\":\"vendor_name\",\"paymentName\":\"payment_name\",\"purchaseCode\":\"po_code\",\"purchaseAmount\":\"purchase_amount\",\"purchaseOrderSaleAmount\":\"sale_amount\",\"transferPrice\":\"sale_price\",\"transferNum\":\"sale_num\",\"transferAmount\":\"sale_pre_amount\",\"transferVendorName\":\"vendor_name\",\"orderStatus\":\"member_purchase_order_status\",\"invoiceStatus\":\"invoice_status\",\"buyer\":\"buyer\",\"orgName\":\"organization_name\",\"purchaseRate\":\"tax_rate\",\"deliveryTime\":\"delivery_time\",\"cloudOrderId\":\"cloud_order_id\",\"returnNumber\":\"return_number\",\"cloudOrderGoodsStatus\":\"transfer_order_goods_status\",\"invoiceType\":\"invoice_type\",\"cloudOrderGoodsId\":\"cloud_order_goods_id\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {

            if (m.get("time") != null) {
                m.put("time", DateUtils.format2DateStr2((Date) m.get("time")));
            }

            if (m.get("deliveryTime") != null) {
                m.put("deliveryTime", DateUtils.format2DateStr2((Date) m.get("deliveryTime")));
            }

            if (m.get("num") != null) {
                m.put("num", new BigDecimal(m.get("num").toString()).doubleValue());
            }

            if (m.get("price") != null) {
                m.put("price", new BigDecimal(m.get("price").toString()).doubleValue());
            }

            if (m.get("amount") != null) {
                m.put("amount", new BigDecimal(m.get("amount").toString()).doubleValue());
            }
            if (m.get("purchaseAmount") != null) {
                m.put("purchaseAmount", new BigDecimal(m.get("purchaseAmount").toString()).doubleValue());
            }
            if (m.get("purchaseOrderSaleAmount") != null) {
                m.put("purchaseOrderSaleAmount", new BigDecimal(m.get("purchaseOrderSaleAmount").toString()).doubleValue());
            }
            if (m.get("transferPrice") != null) {
                m.put("transferPrice", new BigDecimal(m.get("transferPrice").toString()).doubleValue());
            }
            if (m.get("transferNum") != null) {
                m.put("transferNum", new BigDecimal(m.get("transferNum").toString()).doubleValue());
            }
            if (m.get("transferAmount") != null) {
                m.put("transferAmount", new BigDecimal(m.get("transferAmount").toString()).doubleValue());
            }
            if (m.get("grossProfitRate") != null) {
                m.put("grossProfitRate", String.valueOf(new BigDecimal(m.get("grossProfitRate").toString()).doubleValue()));
            }
            if (m.get("accountPeriod") != null) {
                m.put("accountPeriod", String.valueOf(new BigDecimal(m.get("accountPeriod").toString()).doubleValue()));
            }

            if (m.get("orderStatus") != null && StringUtils.isNotBlank(m.get("orderStatus").toString())) {
                m.put("orderStatus", MemberPurchaseOrderEnum.get(Integer.valueOf(m.get("orderStatus").toString())));
            }

            if (m.get("invoiceStatus") != null && StringUtils.isNotBlank(m.get("invoiceStatus").toString())) {
                m.put("invoiceStatus", InvoiceStatus.get(Integer.valueOf(m.get("invoiceStatus").toString())));
            }

            BigDecimal returnNum = getRefundedNum(m.get("cloudOrderGoodsId").toString());
            if (returnNum != null) {
                m.put("returnNumber", returnNum.doubleValue());
            }

            if (m.get("cloudOrderGoodsStatus") != null) {
                m.put("cloudOrderGoodsStatus", OrderGoodsStatusEnum.valueOf(m.get("cloudOrderGoodsStatus").toString()).des);
            }

            if (m.get("invoiceType") != null && StringUtils.isNotBlank(m.get("invoiceType").toString())) {
                m.put("invoiceType", InvoiceApplyTypeEnum.get(Integer.valueOf(m.get("invoiceType").toString())));
            }
            if (m.get("platformName") != null) {
                m.put("platformName", PlatformConst.PLATFORM_ORGANIZATIONS_INVOICE_INFO.get(m.get("platformName").toString()));
            }
            //发票号码
            if (m.get("purchase_id") != null) {
                m.put("invoiceNumber", getListPurchaseInvoice(m.get("purchase_id").toString()));
            }
            return m;

        }).collect(Collectors.toList());

        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购订单商品-导出参数:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("purchase_order_goods_report", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }


    /**
     * 转采管理-采购付款-导出列表
     *
     * @param bo
     * @return
     */
    @Path("exporPurchasePaymentReport")
    @POST
    @Operation(summary = "转采管理-采购付款-导出列表", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporPurchasePaymentReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        String mpgTableName = getTableName(ModelConst.T_PURCHASE_REQUEST_PAYMENT_DETAIL);
        String mpoTableName = getTableName(ModelConst.T_PURCHASE_REQUEST_PAYMENT);
        String tosTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER);
        String ttvTableName = getTableName(ModelConst.T_TRANSFER_VENDOR);
        String tpaTableName = getTableName(ModelConst.T_PAY_ACCOUNT);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append(" select mpg.createdTime time,mpo.memo,mpg.payment_detail_status `status`,mpg.payment_id paymentId,tos.po_code poCode, " +
                " mpg.payment,tos.vendor_name vendorName,tos.invoice_rate rate,tos.payment_name paymentName,mpo.full_name applicantName, " +
                " tos.cloud_order_ids cloudOrderIds,tos.buyer,tos.platform_name platformName,tpa.`name` payName,ttv.bank vendorBank,ttv.account_number accountNumber " +
                " from " + mpgTableName + " AS mpg " +
                " INNER JOIN " + mpoTableName + " AS mpo on mpg.payment_id = mpo.id " +
                " LEFT JOIN " + tosTableName + " AS tos on mpg.member_purchase_order_id = tos.id " +
                " LEFT JOIN " + ttvTableName + " AS ttv on ttv.id = tos.vendor_id " +
                " LEFT JOIN " + tpaTableName + " AS tpa on tpa.id = tos.pay_account_id where mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" and mpg.id in (:id) ");
        parameter.put("id", ids);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        log.info("------------------------转采管理-采购付款-导出列表 exporPurchasePaymentReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"time\":\"createdTime\",\"memo\":\"memo\",\"status\":\"payment_detail_status\",\"poCode\":\"po_code\",\"payment\":\"payment\",\"vendorName\":\"vendor_name\",\"rate\":\"invoice_rate\",\"vendorBank\":\"bank\",\"accountNumber\":\"account_number\",\"paymentName\":\"payment_name\",\"applicantName\":\"full_name\",\"paymentId\":\"payment_id\",\"cloudOrderIds\":\"cloud_order_ids\",\"buyer\":\"buyer\",\"payName\":\"pay_name\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            if (m.get("time") != null) {
                m.put("time", DateUtils.format2DateStr2((Date) m.get("time")));
            }
            if (m.get("status") != null && StringUtils.isNotBlank(m.get("status").toString())) {
                m.put("status", PurchaseRequestEnum.get(Integer.valueOf(m.get("status").toString())));
            }
            if (m.get("payment") != null) {
                m.put("payment", new BigDecimal(m.get("payment").toString()).doubleValue());
            }
            if (m.get("rate") != null) {
                m.put("rate", new BigDecimal(m.get("rate").toString()).doubleValue());
            }
            return m;
        }).collect(Collectors.toList());

        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购付款-导出参数:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("purchase_payment_report", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }

    /**
     * 转采管理-采购付款-打印付款单
     *
     * @param bo
     * @return
     */
    @Path("printPaymentReport")
    @POST
    @Operation(summary = "转采管理-采购付款-打印付款单", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse printPaymentReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }
        String mpgTableName = getTableName(ModelConst.T_PURCHASE_REQUEST_PAYMENT_DETAIL);
        String mpoTableName = getTableName(ModelConst.T_PURCHASE_REQUEST_PAYMENT);
        String tosTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER);
        String ttvTableName = getTableName(ModelConst.T_TRANSFER_VENDOR);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append(" SELECT mpo.createdTime time,mpo.id id,mpo.full_name applyName,ttv.bank bank,ttv.account_number bankAccountNumber, " +
                " tos.vendor_name vendorName,mpo.memo,mpo.print_counter printCounter,tos.platform_name platformName,mpg.id detailId, " +
                " tos.po_code poCode,tos.purchase_amount purchaseAmount,tos.gross_profit_margin grossProfitMargin,mpg.payment,tos.customer_name customerName, " +
                " tos.cloud_order_ids customerOrderId,tos.sale_amount saleAmount  FROM " + mpgTableName + " AS mpg " +
                "INNER JOIN " + mpoTableName + " AS mpo ON mpo.id = mpg.payment_id " +
                "LEFT JOIN " + tosTableName + " AS tos ON mpg.member_purchase_order_id = tos.id " +
                "LEFT JOIN " + ttvTableName + " AS ttv ON ttv.id = tos.vendor_id  where mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" and mpg.id in (:id) ");
        parameter.put("id", ids);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        log.info("------------------------转采管理-采购付款-打印付款单 printPaymentReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"applyName\":\"full_name\",\"time\":\"createdTime\",\"vendorName\":\"vendor_name\",\"bank\":\"bank\",\"memo\":\"memo\",\"detailId\":\"detailId\",\"poCode\":\"po_code\",\"customerOrderId\":\"member_purchase_order_id\",\"customerName\":\"customer_name\",\"saleAmount\":\"sale_amount\",\"purchaseAmount\":\"purchase_amount\",\"bankAccountNumber\":\"bank_number\",\"payment\":\"payment\",\"grossProfitMargin\":\"gross_profit_margin\",\"printCounter\":\"printCounter\",\"id\":\"id\",\"platformName\":\"platformName\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> updatePaymentList = new ArrayList<>();
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            if (m.get("time") != null) {
                m.put("time", DateUtils.format2DateStr2((Date) m.get("time")));
            }
            Map<String, Object> updatePayment = new HashMap<>();
            updatePayment.put("id", m.get("id"));
            if (m.get("printCounter") != null && StringUtils.isNotBlank(m.get("printCounter").toString())) {
                m.put("printCounter", BigDecimalUtils.add(BigDecimalUtils.isNull(m.get("printCounter")), BigDecimal.valueOf(1)).intValue());
                updatePayment.put("print_counter", m.get("printCounter"));
            } else {
                m.put("printCounter", 1);
                updatePayment.put("print_counter", 1);
            }
            updatePaymentList.add(updatePayment);

            if (m.get("payment") != null) {
                m.put("payment", new BigDecimal(m.get("payment").toString()).doubleValue());
            }

            if (m.get("purchaseAmount") != null) {
                m.put("purchaseAmount", new BigDecimal(m.get("purchaseAmount").toString()).doubleValue());
            }

            if (m.get("grossProfitMargin") != null) {
                m.put("grossProfitMargin", new BigDecimal(m.get("grossProfitMargin").toString()).doubleValue());
            }

            if (m.get("saleAmount") != null) {
                m.put("saleAmount", new BigDecimal(m.get("saleAmount").toString()).doubleValue());
            }
            return m;
        }).collect(Collectors.toList());

        SingleResponse<BO> response = BoServiceUtils.updateMainBo(ModelConst.T_PURCHASE_REQUEST_PAYMENT, updatePaymentList);
        log.info("======================打印采购付款单 更新打印次数结果 result：{}", response);

        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购付款-打印付款单:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("purchase/print_payment_report.jrxml", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }

    /**
     * 转采管理-采购收票-导出列表
     *
     * @param bo
     * @return
     */
    @Path("exporPurchaseInvoiceReport")
    @POST
    @Operation(summary = "转采管理-采购收票-导出列表", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporPurchaseInvoiceReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        String mpgTableName = getTableName(ModelConst.T_PURCHASE_INVOICE_DETAIL);
        String mpoTableName = getTableName(ModelConst.T_PURCHASE_INVOICE);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append(" SELECT mpg.createdTime time,mpg.memo,mpg.purchase_invoice_status status,mpg.purchase_invoice_id invoiceId,mpg.invoice_time invoiceTime, " +
                " mpg.invoice_price invoicePrice,mpg.title invoiceTitle,tos.invoice_number invoiceNumber,tos.applicant applier,tos.invoice_rate invoiceRate, " +
                " tos.invoice_amount invoiceAmount,tos.po_code poCode,tos.purchase_amount purchaseAmount,tos.financial_confirm_name financialConfirmer, " +
                " tos.financial_confirm_time financialConfirmerTime  FROM " + mpgTableName + " AS mpg " +
                "LEFT JOIN " + mpoTableName + " AS tos ON mpg.purchase_invoice_id = tos.id WHERE mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" and tos.id in (:id) ");
        parameter.put("id", ids);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        log.info("------------------------转采管理-采购收票-导出列表 exporPurchasePaymentReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"time\":\"createdTime\",\"memo\":\"memo\",\"status\":\"purchase_invoice_status\",\"poCode\":\"po_code\",\"purchaseAmount\":\"purchase_amount\",\"applier\":\"applicant\",\"invoiceAmount\":\"invoice_amount\",\"invoiceTitle\":\"title\",\"invoiceNumber\":\"invoice_number\",\"invoicePrice\":\"invoice_price\",\"invoiceRate\":\"invoice_rate\",\"invoiceTime\":\"invoice_time\",\"financialConfirmer\":\"financial_confirmer\",\"financialConfirmerTime\":\"financial_confirm_time\",\"invoiceId\":\"id\"}";
        JSONObject exportJson = JSON.parseObject(exportField);

        data.stream().forEach(m -> {


            if (m.get("time") != null) {
                m.put("time", DateUtils.format2DateStr2((Date) m.get("time")));
            }
            if (m.get("invoiceTime") != null) {
                m.put("invoiceTime", DateUtils.format2DateStr2((Date) m.get("invoiceTime")));
            }
            if (m.get("financialConfirmerTime") != null) {
                m.put("financialConfirmerTime", DateUtils.format2DateStr2((Date) m.get("financialConfirmerTime")));
            }
            if (m.get("status") != null && StringUtils.isNotBlank(m.get("status").toString())) {
                m.put("status", PurchaseInvoiceEnum.get(Integer.valueOf(m.get("status").toString())));
            }
            if (m.get("purchaseAmount") != null) {
                m.put("purchaseAmount", new BigDecimal(m.get("purchaseAmount").toString()).doubleValue());
            }
            if (m.get("invoiceAmount") != null) {
                m.put("invoiceAmount", new BigDecimal(m.get("invoiceAmount").toString()).doubleValue());
            }
            if (m.get("invoicePrice") != null) {
                m.put("invoicePrice", new BigDecimal(m.get("invoicePrice").toString()).doubleValue());
            }
            if (m.get("invoiceRate") != null) {
                m.put("invoiceRate", new BigDecimal(m.get("invoiceRate").toString()).doubleValue());
            }
        });

        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购收票-导出参数:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(data));
        }
        ReportUtils.exportReport("purchase_invoice_report", reportType.getId(), data);

        return SingleResponse.buildSuccess();
    }


    /**
     * 转采管理-采购订单明细-打印采购合同
     *
     * @param bo
     * @return
     */
    @Path("exporPurchaseOrderPrintReport")
    @POST
    @Operation(summary = "转采管理-采购订单明细-打印采购合同", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporPurchaseOrderPrintReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        String mpgTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER_GOODS);
        String mpoTableName = getTableName(ModelConst.T_MEMBER_PURCHASE_ORDER);
        String togTableName = getTableName(ModelConst.T_TRANSFER_ORDER_GOODS);
        String tosTableName = getTableName(ModelConst.T_TRANSFER_ORDER);
//        String tovTableName = getTableName(ModelConst.T_TRANSFER_VENDOR);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append("select " +
                "case when mpg.cloud_order_id is null or mpg.cloud_order_id='' then tos.cloud_order_id end as cloud_order_id, mpg.*,mpo.*,tog.*,tos.*  from " + mpgTableName + " mpg " +
                "INNER JOIN " + mpoTableName + " mpo on mpg.member_purchase_order_id = mpo.id " +
                "LEFT JOIN " + togTableName + " tog on tog.id = mpg.transfer_order_goods_id " +
                "LEFT JOIN " + tosTableName + " tos on tos.id = tog.transfer_order_id " +
//                "LEFT JOIN " + tovTableName + " tov on tov.id = mpo.vendor_id " +
                "where mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" and mpg.id in (:id) ");
        parameter.put("id", ids);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        log.info("------------------------转采管理-采购订单商品列表分页查询 exporPurchaseOrderPrintReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"fullName\":\"vendor_name\",\"id\":\"id\",\"brand\":\"brand\",\"name\":\"name\",\"unit\":\"unit\",\"amount\":\"amount\",\"time\":\"createdTime\",\"num\":\"num\",\"price\":\"price\",\"poCode\":\"po_code\",\"cloudOrderIds\":\"cloud_order_ids\",\"vendorName\":\"vendor_name\",\"transferVendorContacts\":\"transfer_order_ids\",\"transferVendorMobile\":\"phone\",\"transferVendorEmail\":\"email\",\"mobile\":\"phone\",\"email\":\"email\",\"cloudOrderId\":\"cloud_order_id\",\"modelAndSpec\":\"model\",\"invoiceRate\":\"invoice_rate\",\"memo\":\"memo\",\"deliveryTime\":\"delivery_time\",\"receiveMessage\":\"receiver\",\"paymentName\":\"payment_name\",\"preAmount\":\"pre_amount\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            Map<String, Object> mf = new HashMap<>();
            for (String key : exportJson.keySet()) {
                mf.put(exportJson.getString(key), m.get(key));
            }
            return mf;
        }).collect(Collectors.toList());

        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购订单明细-打印采购合同:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("purchase/purchase_order_print_report.jrxml", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }

    /**
     * 转采管理-采购订单明细-打印收票单
     *
     * @param bo
     * @return
     */
    @Path("exporPurchaseInvoicePrint")
    @POST
    @Operation(summary = "转采管理-采购收票明细-打印收票单", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporPurchaseInvoicePrint(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        SingleResponse<BOList> singleResponse = BoQueryUtils.Builder(ModelConst.T_MEMBER_PURCHASE_ORDER)
                .condition()
                .in("id", ids)
                .End().listBO();
        if (!singleResponse.isSuccess()) {
            return singleResponse;
        }
        List<Map<String, Object>> data = singleResponse.getData().getData();

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"fullName\":\"vendor_name\",\"id\":\"id\",\"brand\":\"brand\",\"name\":\"name\",\"unit\":\"unit\",\"amount\":\"purchase_amount\",\"time\":\"createdTime\",\"num\":\"num\",\"price\":\"price\",\"poCode\":\"po_code\",\"cloudOrderIds\":\"cloud_order_ids\",\"vendorName\":\"vendor_name\",\"transferVendorContacts\":\"transfer_order_id\",\"transferVendorMobile\":\"phone\",\"transferVendorEmail\":\"postal\",\"mobile\":\"phone\",\"email\":\"email\",\"cloudOrderId\":\"cloud_order_id\",\"modelAndSpec\":\"model\",\"invoiceRate\":\"invoice_rate\",\"memo\":\"memo\",\"deliveryTime\":\"delivery_time\",\"receiveMessage\":\"remark_message\",\"paymentName\":\"payment_name\",\"preAmount\":\"pre_amount\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            Map<String, Object> mf = new HashMap<>();
            for (String key : exportJson.keySet()) {
                mf.put(exportJson.getString(key), m.get(key));
            }
            return mf;
        }).collect(Collectors.toList());


        if (log.isDebugEnabled()) {
            log.debug("======================转采管理-采购收票明细-打印收票单:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("purchase/purchase_invoice_print.html", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }


}
